﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Platform.Applications.Models;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Platform.Applications.Web
{
    /// <summary>
    /// 
    /// </summary>
    [NoCache, AllowAnonymous]
    public class PlatformController : MvcControllerBase
    {
        /// <summary>
        /// 
        /// </summary>
        [AutoWired]
        protected IPlatformService Component
        {
            get;
            set;
        }
        /// <summary>
        /// 进入单个模块(此api仅响应模块跳转地址，由模块内鉴权)
        /// </summary>
        /// <param name="moduleId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Module(string moduleId)
        {
            SystemNavModule module = Component.GetSystemModule(moduleId);
            RedirectResponse<SystemNavModule> response = new RedirectResponse<SystemNavModule>(module);
            return ResponseResult(response);
        }

        /// <summary>
        /// 获取环境变量等信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Response<SystemGlobalConfig> Env()
        {
            var envConfig = Component.GetSystemGlobalConfig();

            return envConfig.CreateResponse();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<string[]> Roles([FromBody] RolesQuery rolesQuery)
        {
            var roles = Component.GetRoles(rolesQuery.FullUri, rolesQuery.EntryUri);
            return roles.CreateResponse();
        }
    }
}
